package com.proton.carepatchtemp.ble;

import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothGatt;
import android.util.ArrayMap;

/**
 * Created by MoonlightSW on 2017/5/19.
 */

public class BleManager {

    public ArrayMap<String, BluetoothDevice> mBluetoothDeviceList = new ArrayMap<>(); //  已连接的设备集合
    public ArrayMap<String, BluetoothGatt> mBluetoothGattList = new ArrayMap<>();   //  已连接的设备Gatt服务集合

    private BleManager() {
    }

    public static BleManager get() {
        return Holder.INSTANCE;
    }

    public ArrayMap<String, BluetoothDevice> getDeviceList() {
        return mBluetoothDeviceList;
    }

    public ArrayMap<String, BluetoothGatt> getGattlist() {
        return mBluetoothGattList;
    }

    /**
     * 关闭所有设备连接
     */
    public void closeAll() {
        for (BluetoothGatt gatt :
                mBluetoothGattList.values()) {
            if (null != gatt) {
                gatt.close();
            }
        }

        mBluetoothDeviceList.clear();
        mBluetoothGattList.clear();
    }

    private static class Holder {
        private static final BleManager INSTANCE = new BleManager();
    }
}
